[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark - #1156
[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark#1156bosd wants to merge 58 commits into
Conversation
When no background configuration is present on the report definition, don't try to browse the report model especially because this breaks some upstream reports (see odoo/odoo#23389)
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-11.0/reporting-engine-11.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-11-0/reporting-engine-11-0-report_qweb_pdf_watermark/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-12.0/reporting-engine-12.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-report_qweb_pdf_watermark/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-12.0/reporting-engine-12.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-report_qweb_pdf_watermark/
external_dependencies
[MIG] report_qweb_pdf_watermark: Migration to 15.0
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-16.0/reporting-engine-16.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_pdf_watermark/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-16.0/reporting-engine-16.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_pdf_watermark/es/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-17.0/reporting-engine-17.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-17-0/reporting-engine-17-0-report_qweb_pdf_watermark/it/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-18.0/reporting-engine-18.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-report_qweb_pdf_watermark/tr/
When printing a document in a multi-company environment, the company watermark was selected based on self.env.company (the company currently active in the UI switcher) rather than the company of the document being printed. This caused the wrong watermark to appear when a user switched to company B and printed an invoice belonging to company A (or vice versa), as reported in OCA#1134. Fix by introducing a _get_watermark_company() helper that returns the document's company_id when available, falling back to self.env.company otherwise.
There was a problem hiding this comment.
The last commit looks good. Minor optional comment from me.
However, this PR has 58 commits.. it looks like a rebase gone wrong. Can you clean it up? EDIT: Ok I see you mentioned you're basing on top of #1091. Sorry for the noise
| model_name = self.model or report_sudo.model | ||
| docs = self.env[model_name].browse(docids) | ||
| if docs and "company_id" in docs._fields and docs[:1].company_id: | ||
| return docs[:1].company_id |
There was a problem hiding this comment.
Maybe we can follow this core pattern: https://github.com/OCA/odoo/blob/214244ac6b4b1f4747c91e7247c5536cdea0b415/odoo/orm/models.py#L4044-L4049
Something like:
if "company_id" in docs._fields:
company = docs.company_id[:1]
elif "company_ids" in docs._fields:
company = docs.company_ids[:1]
return company or self.env.company|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
Summary
Closes #1134.
When printing a document in a multi-company environment, the company watermark is selected based on
self.env.company(the company currently active in the UI switcher) rather than the company of the document being printed. This causes the wrong watermark to appear when a user switches to company B and prints an invoice belonging to company A (or vice versa).Changes
_get_watermark_company()helper that returns the document'scompany_idwhen available, falling back toself.env.companyotherwise.Test plan
self.env.company)Notes
Based on #1091 (the 19.0 migration). Will rebase on 19.0 once that is merged.